{% extends 'layouts/master-page.html' %}
{% block title %}Weakness browsing{% endblock %}
{% block head %}
<!-- css -->
<link href="/static/css/custom/cwe.css" rel="stylesheet" />
{% endblock %}

{% block body_scripts %}
<script>
        $(document).ready(function(){
          $("#dom_filter").on("keyup", function() {
            var value = $(this).val().toLowerCase();
            $("#cweTable tbody tr").filter(function() {
              $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
            });
          });
        });
    </script>
{% endblock %}

{% block content %}
<!-- breadcrumb -->
{% include 'subpages/breadcrumbs.html' %}
<div>
  <table id="cweTable" class="table table-hover table-striped">
    <thead class="thead-dark">
    <tr>
      {% if capec == None %}
      <th width="10%">
        CWE ID
      </th>
      <th>
        <div class="input-group">
          Description
          <form class="form-inline search_form">
            <input class="form-control mr-sm-2" type="search" placeholder="Filter table" aria-label="Search" id="dom_filter">
          </form>
        </div>
      </th>
      {% else %}
      <th>
        CAPEC
      </th>
      <th>
        Related Weakness
      </th>
      {% endif %}
    </tr>
    </thead>
    <tbody>
    {% if capec == None %}
    {% for c in cwes %}
    <tr class="cwe_data">
      <td>
        <a href="/cwe/{{c.id}}">CWE-{{c.id}}</a>
      </td>
      <td>
        {{c.name}}
      </td>
    </tr>
    {% endfor %}
    {% else %}
    {% for c in capec %}
    <tr>
      <td width="20%"><a href="/capec/{{c.id}}">{{c.name}}</a></td>
      <td>
        <a id="colf_{{c.id}}" data-toggle="collapse" href="#collapse{{c.id}}" aria-expanded="false" aria-controls="collapse{{c.id}}">
          <i class="fas fa-chevron-circle-down" style="float:right"></i>
        </a>
        <div class="collapse partial" id="collapse{{c.id}}">
          <table>
            {% for r in c.related_weakness|sortIntLikeStr %}
            <tr>
              <td width="75px">
                <a href="/cwe/{{r}}">CWE-{{r}}</a>
              </td>
              <td>
                {{cwes[r]}}
              </td>
            </tr>
            {% endfor %}
          </table>
        </div>
      </td>
    </tr>
    {% endfor %}
    {% endif %}
    </tbody>
  </table>
</div>
{% endblock %}
